// User extensions can be added here.
//
// Keep this file to avoid  mystifying "Invalid Character" error in IE

// The ID of the Flex SWF object.  This is configurable via setFlexApp command.
var flexApp = "flexApp";

// All do* methods on the Selenium prototype are added as actions.
// Eg add a typeRepeated action to Selenium, which types the text twice into a text box.
// The typeTwiceAndWait command will be available automatically


Selenium.prototype.doChangeFx = function( locator, args ) {
    var element = this.page().findElement( flexApp );

	element.runCommand( locator, "Change", args );
};

Selenium.prototype.doClickFx = function( locator, args ) {
    var element = this.page().findElement( flexApp );

	element.runCommand( locator, "Click", args );
};

Selenium.prototype.doDragDropFx = function( locator, args ) {
    var element = this.page().findElement( flexApp );

	element.runCommand( locator, "DragDrop", args );
};

Selenium.prototype.doDragStartFx = function( locator, args ) {
    var element = this.page().findElement( flexApp );

	element.runCommand( locator, "DragStart", args );
};

Selenium.prototype.doInputFx = function( locator, args ) {
    var element = this.page().findElement( flexApp );

	element.runCommand( locator, "Input", args );
};

Selenium.prototype.doOpenFx = function( locator, args ) {
    var element = this.page().findElement( flexApp );

	element.runCommand( locator, "Open", args );
};

Selenium.prototype.doSelectFx = function( locator, args ) {
    var element = this.page().findElement( flexApp );

	element.runCommand( locator, "Select", args );
};

Selenium.prototype.doSelectTextFx = function( locator, args ) {
    var element = this.page().findElement( flexApp );

	_runCommand( element, locator, "SelectText", args );
};

Selenium.prototype.doSetFlexApp = function( flexId ) {
	flexApp = flexId;
};

Selenium.prototype.doTypeFx = function( locator, args ) {
    var element = this.page().findElement( flexApp );

	element.runCommand( locator, "Type", args );
};

function _runCommand( element, locator, command, args ) {
	var message = element.runCommand( locator, command, args );
	
	if ( message != 'ok' )
	{
		throw new Error( message );
	}
}

// All get* methods on the Selenium prototype result in
// store, assert, assertNot, verify, verifyNot, waitFor, and waitForNot commands.
// E.g. add a getTextLength method that returns the length of the text
// of a specified element.
// Will result in support for storeTextLength, assertTextLength, etc.
Selenium.prototype.getTextFx = function( locator ) {
	var element = this.page().findElement( flexApp );
	
	return element.getFieldValue( locator, "text" );
};